package edu.cuit.avatar.collection;

import java.util.*;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/15 9:08
 */
public class QueueDemo {
    public static void main(String[] args) {
        Queue<String> queue = new LinkedList<>();
        queue.offer("peppa"); //元素被追加到队列末尾
        queue.offer("suzy"); //元素被追加到队列末尾
        queue.offer("pedro"); //元素被追加到队列末尾
        queue.offer("emily"); //元素被追加到队列末尾

        System.out.println(queue.poll()); //peppa
        while(!queue.isEmpty())
            System.out.println(queue.poll());

        System.out.println("============================");
        Deque<String> deque = new LinkedList<>();
        deque.offer("peppa");
        deque.addFirst("jorge");
        deque.addLast("emily");
        while(!deque.isEmpty())
            System.out.println(deque.removeLast());

        System.out.println("===============================");
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();//自然顺序(Comparable)指定优先级
        priorityQueue.add(10); //最高优先级，最先出列
        priorityQueue.add(20);
        priorityQueue.add(20);
        priorityQueue.add(30);
        priorityQueue.add(10); //最高优先级
        priorityQueue.add(40);

        while(!priorityQueue.isEmpty())
            System.out.println(priorityQueue.poll());

        System.out.println("===========================================");
        PriorityQueue<Integer> priorityQueue2 =
                new PriorityQueue<>(11, Collections.reverseOrder()); //比较排序(Comparator)进行排序确定优先级
        priorityQueue2.add(10); //最高优先级，最先出列
        priorityQueue2.add(20);
        priorityQueue2.add(20);
        priorityQueue2.add(30);
        priorityQueue2.add(10); //最高优先级
        priorityQueue2.add(40);

        while(priorityQueue2.size() > 0)
            System.out.println(priorityQueue2.poll());
    }
}
